// #ifdef APP-NVUE
import nvueMixinfrom from '@/common/mixin/nvueMixin.js';
// #endif
export default {
  // #ifdef APP-NVUE
  mixins: [nvueMixinfrom],
  // #endif
  props: {
    info: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      ctx: null,
      previewImageUrl: '',
      shareList: [],
      sharePopup: false,
      showPainter: false,
      posterPopup: false,
    }
  },
  created() {
    this.shareList = [
      // #ifdef MP-WEIXIN||APP-PLUS-NVUE
      {

        title: this.$t('微信好友'),
        icon: this.benbenImageSrcResolution('weixin.png', 'global'),
        type: 'weixin',
        scene: 'WXSceneSession',
      },
      // #endif
      // #ifdef APP-PLUS-NVUE
      {
        title: this.$t('朋友圈'),
        icon: this.benbenImageSrcResolution('pengyouquan.png', 'global'),
        type: 'weixin',
        scene: 'WXSenceTimeline',
      },
      // #endif
      {
        title: this.$t('复制链接'),
        icon: this.benbenImageSrcResolution('copy.png', 'global'),
        type: 'link',
      },
      {
        title: this.$t('海报'),
        icon: this.benbenImageSrcResolution('poster.png', 'global'),
        type: 'image',
      },
      {
        title: this.$t('拉黑'),
        icon: this.benbenImageSrcResolution('block.png', 'global'),
        type: 'block',
      },
      {
        title: this.$t('举报'),
        icon: this.benbenImageSrcResolution('feedback.png', 'global'),
        type: 'feedback',
      },
      {
        title: this.$t('删除'),
        icon: this.benbenImageSrcResolution('delet.png', 'global'),
        type: 'delet',
      },
      {
        title: this.$t('编辑'),
        icon: this.benbenImageSrcResolution('edit.png', 'global'),
        type: 'edit',
      },
    ]

  },
  computed: {
    systemInfo() {
      return this.$store.state.SystemInfo
    },
    title() {
      if (!this.info.title) {
        return ''
      }
      if (this.info.title.length < 24) {
        return this.info.title
      }
      if (this.info.title) {
        return this.info.title.substring(0, 24) + '...'
      }
    },
    showShareList() {
      let showTypes = ['weixin', 'link', 'image',]
      this.info.is_self ? showTypes.push('delet', 'edit') : showTypes.push('block', 'feedback')
      return this.shareList.filter(item => showTypes.includes(item.type))
    },
  },
  watch: {
    sharePopup(val) {
      if (!val) {
        this.$emit('close')
      }
    }
  },

  methods: {

    success(e) {
      this.showPainter = false
      this.posterPopup = true
      uni.hideLoading()
      this.previewImageUrl = e
    },
    fail(error) {
      console.log('fail', error);
      uni.hideLoading()
      this.$message.error(this.$t('海报生成失败'))
    },

    // 打开弹窗
    open() {
      this.sharePopup = true
      this.previewImageUrl = ''
    },
    // 关闭弹窗
    close() {
      this.sharePopup = false
      this.posterPopup = false
      this.previewImageUrl = ''
    },

    // 分享
    share(item) {
      let _provider = item.type
      switch (_provider) {
        case 'weixin':
          let share = {
            provider: _provider,
            type: this.info.shareType,
            title: '推荐给你一个视频',
            scene: item.scene,
            summary: this.info.title,
            imageUrl: this.info.coverImg,
            success: (res) => {
              this.close()
            },
            fail: (err) => {
              console.log('分享失败', err)
              this.$message.error(this.$t('分享失败'))
            },
          }
          if (this.info.shareType == 5) {
            share.miniProgram = this.info.miniProgram
          }
          if (this.info.shareType == 0) {
            share.href = this.info.appShareUrl
          }
          uni.share(
            share
          )
          break
        case 'link':
          uni.setClipboardData({
            data: this.info.appShareUrl,
            success: () => {
              this.$message.info(this.$t('复制成功'))
              this.close()
            },
          })
          break
        case 'image':
          // this.createPoster()
          this.previewImageUrl = ''
          this.showPainter = true
          uni.showLoading({
            title: this.$t('生成中...'),
            mask: true
          })
          break
        case 'block':
        case 'feedback':
        case 'delet':
        case 'edit':
          this.sharePopup = false
          this.$emit('handleMenu', { type: _provider, data: this.info })
          break
      }
    },
    // 保存图片
    async saveImage() {
      if (!this.previewImageUrl) return
      await this.syncUniApi('saveImageToPhotosAlbum', { filePath: this.previewImageUrl })
      this.$message.info(this.$t('保存成功'))
      this.close()
    },
  },

}
